
#include <iostream>
#include <unordered_set>
#include <fstream>
#include <string>

using std::cout;
using std::endl;
using std::unordered_set;
using std::ifstream;
using std::string;

size_t nBytesCode(const char ch);
std::size_t length(const std::string &str);

void test() {
    ifstream ifs("./stop_words_zh.txt");
    string word;
    string stmp;
    unordered_set<string> stopWords;

    while(ifs >> stmp) {
        cout << stmp << endl;
        size_t sz = stmp.size();
        size_t nBytes = nBytesCode(stmp[0]);
        word = stmp.substr(0, nBytes);
        /* cout << "size = " << sz << endl; */
        /* for(size_t idx = 0; idx < sz; idx += 3) { */
        /*     string wtmp = stmp.substr(idx, 3); */
        /*     word += wtmp; */
        /* } */
        stopWords.insert(word);
        word.clear();
    }

    /* for(auto &iter : stopWords) { */
    /*     cout << iter << endl; */
    /* } */

    cout << stopWords.count("的") << endl;
    cout << stopWords.size() << endl;
}

int main()
{
    test();
    return 0;
}

size_t nBytesCode(const char ch)
{
    if(ch & (1 << 7))
    {
        int nBytes = 1;
        for(int idx = 0; idx != 6; ++idx)
        {
            if(ch & (1 << (6 - idx)))
            {
                ++nBytes;   
            }
            else
                break;
        }
        return nBytes;
    }
    return 1;
}  

std::size_t length(const std::string &str)
{
    std::size_t ilen = 0;
    for(std::size_t idx = 0; idx != str.size(); ++idx)
    {
        int nBytes = nBytesCode(str[idx]);
        idx += (nBytes - 1);
        ++ilen;
    }
    return ilen;
}
